<?php

function showTable_5($n5, $n4, $n3, $n2, $n1)
{
    $tempStr = "<td style=\"border-left-width:4px;\">{$n5}</td><td>{$n4}</td><td>{$n3}</td><td>{$n2}</td><td style=\"border-right-width:4px;\">{$n1}</td>";
    return $tempStr;
}

function showTable_8h($n1, $n2, $n3, $n4, $n5, $n6)
{
    $tempStr = "<td style=\"border-left-width:4px;\">{$n1}</td><td>{$n2}</td><td>{$n3}</td><td>{$n4}</td><td>{$n5}</td><td style=\"border-right-width:4px;\">{$n6}</td>";
    return $tempStr;
}

function showTable_two_5($n1, $n2)
{
    $tempStr = "<td style=\"border-left-width:4px;\">{$n1}</td><td>{$n2}</td>";
    return $tempStr;
}

function show_total_8h($n1, $n2, $n3, $n4, $n5)
{
    $tempStr = "<td style=\"border-left-width:4px;\">{$n1}</td><td>{$n2}</td><td>{$n3}</td><td>{$n4}</td><td>{$n5}</td>";
    return $tempStr;
}

if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
require_once( "class_3d/CheckMode_3d.php" );
$gametype = intval(getvar("gametype"));
$chk = new CheckMode_3d($curruser['acl'], 5, $gametype);
$chk->checkShow3dPage();
$show3D3S = $chk->show3D3S;
unset($chk);
$ui = new UI_3D(true);
$tpl = new Template2();
$conf = new Config();
include_once( "class_5h/MyLotto_5h.php" );
$MyLotto_5h = new MyLotto_5h($gametype);
$tbl = $g_gametype_3d[$gametype]['en'];
$tblName = $g_gametype_3d[$gametype]['ch'];
$page = getvar("page");
$page = $page == "" ? 1 : intval($page);
$ymdhis = date("Y-m-d H:i:s");
$rs = $MyLotto_5h->getDataList3s($page, 10, $show3D3S);
$showOpenTime = true;
$number = intval(getvar("number"));
if ($number == "")
{
    $number = 1;
}
if ($rs->eof)
{
    $list = "<tr><td colspan=41>目前无{$tblName}相关资料</td></tr>";
}
else if ($gametype == 20)
{
    $list = "<tbody id=\"tbdList\">";
    while (!$rs->eof)
    {
        $n5 = $rs->f['n5'] == 0 - 1 ? "" : $rs->f['n5'];
        $n4 = $rs->f['n4'] == 0 - 1 ? "" : $rs->f['n4'];
        $n3 = $rs->f['n3'] == 0 - 1 ? "" : $rs->f['n3'];
        $n2 = $rs->f['n2'] == 0 - 1 ? "" : $rs->f['n2'];
        $n1 = $rs->f['n1'] == 0 - 1 ? "" : $rs->f['n1'];
        $openFlag = $MyLotto_5h->checkOpen($rs->f['n3'], $rs->f['n2'], $rs->f['n1'], $rs->f['n4'], $rs->f['n5']);
        if ($showOpenTime)
        {
            $classStr = $ymdhis <= $rs->f['openbet'] && $rs->f['startbet'] <= $ymdhis ? "td6" : "td2";
        }
        else
        {
            $classStr = $rs->f['open'] == date("Y-m-d") ? "td6" : "td2";
        }
        $list .= "<tr class=\"" . $classStr . "\" align=\"center\">";
        $dateNum = date("w", strtotime($rs->f['open']));
        $list .= "<td nowrap>" . $rs->f['round'] . "</td>";
        $list .= "<td style=\"border-left-width:4px;\" nowrap>" . $g_weekname[$dateNum] . "</td>";
        $list .= "<td style=\"border-left-width:4px; border-right-width:4px;\" nowrap>" . $rs->f['open'] . "</td>";
        if ($showOpenTime)
        {
            $openbetIntTemp = strtotime($rs->f['openbet']);
            if (date("Y-m-d", $openbetIntTemp) != $rs->f['open'])
            {
                $list .= "<td nowrap class=\"td14\">";
            }
            else
            {
                $list .= "<td nowrap>";
            }
            $list .= date("H:i", $openbetIntTemp) . "</td>";
        }
        if ($openFlag)
        {
            $list .= "<td style=\"border-left-width:4px;\" nowrap class=\"ball3dBgS2\">" . d2($n1) . "</td>";
            $list .= "<td nowrap class=\"ball3dBgS2\">" . d2($n2) . "</td>";
            $list .= "<td nowrap class=\"ball3dBgS2\">" . d2($n3) . "</td>";
            $list .= "<td nowrap class=\"ball3dBgS2\">" . d2($n4) . "</td>";
            $list .= "<td nowrap style=\"border-right-width:4px;\" class=\"ball3dBgS3\">" . d2($n5) . "</td>";
            $list .= showTable_5($MyLotto_5h->showText($rs->f['p1'], "sd"), $MyLotto_5h->showText($rs->f['p2'], "sd"), $MyLotto_5h->showText($rs->f['p3'], "sd"), $MyLotto_5h->showText($rs->f['p4'], "sd"), $MyLotto_5h->showText($rs->f['p5'], "sd", false));
            $list .= showTable_5($MyLotto_5h->showText($rs->f['p1'], "bs"), $MyLotto_5h->showText($rs->f['p2'], "bs"), $MyLotto_5h->showText($rs->f['p3'], "bs"), $MyLotto_5h->showText($rs->f['p4'], "bs"), $MyLotto_5h->showText($rs->f['p5'], "bs", false));
            $list .= showTable_5($MyLotto_5h->showText($rs->f['p1'], "t_bs"), $MyLotto_5h->showText($rs->f['p2'], "t_bs"), $MyLotto_5h->showText($rs->f['p3'], "t_bs"), $MyLotto_5h->showText($rs->f['p4'], "t_bs"), $MyLotto_5h->showText($rs->f['p5'], "t_bs", false));
            $list .= showTable_5($MyLotto_5h->showText($rs->f['p1'], "s_sd"), $MyLotto_5h->showText($rs->f['p2'], "s_sd"), $MyLotto_5h->showText($rs->f['p3'], "s_sd"), $MyLotto_5h->showText($rs->f['p4'], "s_sd"), $MyLotto_5h->showText($rs->f['p5'], "s_sd", false));
            $list .= showTable_5($MyLotto_5h->showText($rs->f['p1'], "color"), $MyLotto_5h->showText($rs->f['p2'], "color"), $MyLotto_5h->showText($rs->f['p3'], "color"), $MyLotto_5h->showText($rs->f['p4'], "color"), $MyLotto_5h->showText($rs->f['p5'], "color"));
            $list .= showTable_5($MyLotto_5h->showText($rs->f['p1'], "four"), $MyLotto_5h->showText($rs->f['p2'], "four"), $MyLotto_5h->showText($rs->f['p3'], "four"), $MyLotto_5h->showText($rs->f['p4'], "four"), $MyLotto_5h->showText($rs->f['p5'], "four", false));
            $list .= showTable_two_5($MyLotto_5h->showText($rs->f['p6'], "total_sd"), $MyLotto_5h->showText($rs->f['p6'], "total_bs"));
        }
        else
        {
            $list .= "<td style=\"border-left-width:4px;\" colspan=\"41\">&nbsp;</td>";
        }
        $list .= "</tr>";
        $rs->movenext();
    }
    $list .= "</tbody>";
}
else
{
    $list = "<tbody id=\"tbdList\">";
    while (!$rs->eof)
    {
        $n8 = $rs->f['n8'] == 0 - 1 ? "" : $rs->f['n8'];
        $n7 = $rs->f['n7'] == 0 - 1 ? "" : $rs->f['n7'];
        $n6 = $rs->f['n6'] == 0 - 1 ? "" : $rs->f['n6'];
        $n5 = $rs->f['n5'] == 0 - 1 ? "" : $rs->f['n5'];
        $n4 = $rs->f['n4'] == 0 - 1 ? "" : $rs->f['n4'];
        $n3 = $rs->f['n3'] == 0 - 1 ? "" : $rs->f['n3'];
        $n2 = $rs->f['n2'] == 0 - 1 ? "" : $rs->f['n2'];
        $n1 = $rs->f['n1'] == 0 - 1 ? "" : $rs->f['n1'];
        $total = $n1 + $n2 + $n3 + $n4 + $n5 + $n6 + $n7 + $n8;
        if ($gametype == 24)
        {
            $n9 = $rs->f['n9'] == 0 - 1 ? "" : $rs->f['n9'];
            $n10 = $rs->f['n10'] == 0 - 1 ? "" : $rs->f['n10'];
            $total = $n1 + $n2;
        }
        $openFlag = $MyLotto_5h->checkOpen($rs->f['n3'], $rs->f['n2'], $rs->f['n1'], $rs->f['n4'], $rs->f['n5'], $rs->f['n6'], $rs->f['n7'], $rs->f['n8']);
        if ($showOpenTime)
        {
            $classStr = $ymdhis <= $rs->f['openbet'] && $rs->f['startbet'] <= $ymdhis ? "td6" : "td2";
        }
        else
        {
            $classStr = $rs->f['open'] == date("Y-m-d") ? "td6" : "td2";
        }
        $list .= "<tr class=\"" . $classStr . "\" align=\"center\">";
        $dateNum = date("w", strtotime($rs->f['open']));
        $list .= "<td nowrap>" . $rs->f['round'] . "</td>";
        $list .= "<td style=\"border-left-width:4px;\" nowrap>" . $g_weekname[$dateNum] . "</td>";
        $list .= "<td style=\"border-left-width:4px; border-right-width:4px;\" nowrap>" . $rs->f['open'] . "</td>";
        if ($showOpenTime)
        {
            $openbetIntTemp = strtotime($rs->f['openbet']);
            if (date("Y-m-d", $openbetIntTemp) != $rs->f['open'])
            {
                $list .= "<td nowrap class=\"td14\">";
            }
            else
            {
                $list .= "<td nowrap>";
            }
            $list .= date("H:i", $openbetIntTemp) . "</td>";
        }
        if ($openFlag)
        {
            if ($gametype == 24)
            {
                $list .= "<td><img src=\"image/pk" . $n1 . ".png\"></td>";
                $list .= "<td><img src=\"image/pk" . $n2 . ".png\"></td>";
                $list .= "<td><img src=\"image/pk" . $n3 . ".png\"></td>";
                $list .= "<td><img src=\"image/pk" . $n4 . ".png\"></td>";
                $list .= "<td><img src=\"image/pk" . $n5 . ".png\"></td>";
                $list .= "<td><img src=\"image/pk" . $n6 . ".png\"></td>";
                $list .= "<td><img src=\"image/pk" . $n7 . ".png\"></td>";
                $list .= "<td><img src=\"image/pk" . $n8 . ".png\"></td>";
                $list .= "<td><img src=\"image/pk" . $n9 . ".png\"></td>";
                $list .= "<td><img src=\"image/pk" . $n10 . ".png\"></td>";
                $list .= "<td style=\"border-left-width:4px;\">" . $MyLotto_5h->showText($rs->f["p" . $number], "sd") . "</td>";
                $list .= "<td>" . $MyLotto_5h->showText($rs->f["p" . $number], "bs") . "</td>";
                if ($number <= 5)
                {
                    $list .= "<td>" . $MyLotto_5h->showText($rs->f["p" . $number], "animal") . "</td>";
                }
                $list .= "<td nowrap ><font class=text02>" . $MyLotto_5h->showText($rs->f["p11"], "sd") . "</font></td>";
                $list .= "<td nowrap ><font class=text02>" . $MyLotto_5h->showText($rs->f["p11"], "bs") . "</font></td>";
                $list .= "<td nowrap >" . $total . "</td>";
            }
            else
            {
                $list .= "<td style=\"border-left-width:4px;\" nowrap class=\"ball_8h_" . ( 18 < $n1 ? "red" : "yellow" ) . "\">" . d2($n1) . "</td>";
                $list .= "<td nowrap class=\"ball_8h_" . ( 18 < $n2 ? "red" : "yellow" ) . "\">" . d2($n2) . "</td>";
                $list .= "<td nowrap class=\"ball_8h_" . ( 18 < $n3 ? "red" : "yellow" ) . "\">" . d2($n3) . "</td>";
                $list .= "<td nowrap class=\"ball_8h_" . ( 18 < $n4 ? "red" : "yellow" ) . "\">" . d2($n4) . "</td>";
                $list .= "<td nowrap class=\"ball_8h_" . ( 18 < $n5 ? "red" : "yellow" ) . "\">" . d2($n5) . "</td>";
                $list .= "<td nowrap class=\"ball_8h_" . ( 18 < $n6 ? "red" : "yellow" ) . "\">" . d2($n6) . "</td>";
                $list .= "<td nowrap class=\"ball_8h_" . ( 18 < $n7 ? "red" : "yellow" ) . "\">" . d2($n7) . "</td>";
                $list .= "<td nowrap class=\"ball_8h_" . ( 18 < $n8 ? "red" : "yellow" ) . "\">" . d2($n8) . "</td>";
                $list .= showTable_8h($MyLotto_5h->showText($rs->f["p" . $number], "sd"), $MyLotto_5h->showText($rs->f["p" . $number], "bs"), $MyLotto_5h->showText($rs->f["p" . $number], "t_bs"), $MyLotto_5h->showText($rs->f["p" . $number], "s_sd"), $MyLotto_5h->showText($rs->f["p" . $number], "three"), $MyLotto_5h->showText($rs->f["p" . $number], "position"), $MyLotto_5h->showText($rs->f["p" . $number], "sd"), $MyLotto_5h->showText($rs->f["p" . $number], "sd"));
                $list .= show_total_8h($total, $MyLotto_5h->showText($rs->f['p9'], "sd"), $MyLotto_5h->showText($rs->f['p9'], "total_tbsArr"), $MyLotto_5h->showText($rs->f['p9'], "total_8hbs"), $MyLotto_5h->showText($rs->f['p9'], "animal"));
            }
        }
        else
        {
            $list .= "<td style=\"border-left-width:4px;\" colspan=\"41\">&nbsp;</td>";
        }
        $list .= "</tr>";
        $rs->movenext();
    }
    $list .= "</tbody>";
}
$htm = $gametype == 20 ? "result_5h.htm" : "result_8h.htm";
if ($gametype == 24)
{
    $htm = "result_pk10.htm";
}
$tpl->load("main", $htm);
$tpl->set("list", $list);
$tpl->set("button", $rs->pagelink());
$tpl->set("gametype", "bgClc_{$gametype}");
$tpl->set("title_gametype", "bgImg_{$gametype}");
$tpl->set("gametypeStr", $tblName);
$tpl->set("chk" . $number, "checked");
$tpl->set("play_gametype", $gametype);

if ($gametype == 24)
{
    if ($number <= 5)
    {
        $colspan = 3;
        $teltlist = "<td width='6%' class=td15 id='bottom-left'>单双</td> <td width='6%' class=td15 id='bottom'>大小</td><td width='6%' class=td15 id='bottom'>龙虎</td>";
    }
    else
    {
        $colspan = 2;
        $teltlist = "<td width='6%' class=td15 id='bottom-left'>单双</td> <td width='6%' class=td15 id='bottom'>大小</td>";
    }
    $tpl->set("colspan", $colspan);
    $tpl->set("teltlist", $teltlist);
}
if ($showOpenTime)
{
    $tpl->set(array ("showOpenTimeTd" => "<td style=\"border-bottom-width=4px;\" rowspan=\"2\" width=\"1%\">开奖<br />时间</td>", "showOpenTimeTd02" => "<td>&nbsp;</td>", "note3s" => "<div>※开奖时间背景颜色为<span class=\"td14\">粉红色</span>时，代表已过凌晨(开奖日期 = 报表日期加一天)</div>"));
}
$jslink = "<script src=\"core/tpl/k2/jquery-1.4.2.min.js\"></script>\n";
$ui->set("jslink", $jslink);
$ui->set("csscode", ".ball3dBg{font-size:20px;} table td{font-size:13px;}");
$ui->header();
echo "<br />";
$tpl->show("main");
$ui->footer();